package com.lfnyxy.service.imp;


import com.lfnyxy.dao.CityRefDao;
import com.lfnyxy.dto.DropVo;
import com.lfnyxy.entity.CityRefEntity;
import com.lfnyxy.query.CityRefQuery;
import com.lfnyxy.service.CityRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CityRefServiceImp implements CityRefService {
    @Autowired
    public CityRefDao cityRefDao;

    public int CreateItem(CityRefEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return cityRefDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(CityRefEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return cityRefDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List<CityRefEntity> QueryPageList(CityRefQuery query) {
        int count = cityRefDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return cityRefDao.QueryPageList(query);
        }
        return null;
    }

    public List<CityRefEntity> QueryAll() {
        return cityRefDao.QueryAll();
    }

    public List<DropVo> QueryDrop(CityRefQuery query) {
        return cityRefDao.QueryDrop(query);
    }

    public CityRefEntity QueryItem(int Id) {
        if (Id > 0) {
            return cityRefDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return cityRefDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(CityRefEntity entity) {
        if (entity != null) {
            return cityRefDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}